<template>
	<view class="index-page">	
		<view class="index-swiper">
			<u-swiper
				class="index-swiper-box"
				:list="swiperList"
				keyName="bannerImg"
				@change="e => current = e.current"
				circular
				:autoplay="true"
				interval="3000"
				previousMargin="22"
				nextMargin="22"
				radius="20"
				bgColor="#16181D"
				border-radius="0"
				height="129"
				:indicator="false"
				@click="swiperClick"
				imgMode="aspectFill"
			>
				<view
					slot="indicator"
					class="indicator"
				>
					<view
						class="indicator__dot"
						v-for="(item, index) in swiperList"
						:key="index"
						:class="[index === current && 'indicator__dot__active']"
					>
						<view class="indicator__dot__active__line"></view>
					</view>
				</view>
			</u-swiper>
		</view>
		<view class="index-main">
			<view class="index-main-box">
				<view class="index-main-chunk" v-if="scrollList.length>0">
					<view class="index-main-chunk-header">
						<view class="_mian-chunk-header-title"><text>神秘盲盒</text></view>
						<view class="_mian-chunk-header-right" @click="toLink('/pages/blindBoxList/blindBoxList')"><image class="_mian-chunk-header-right-icon" src="../../static/img/right-icon.png" mode=""></image></view>
					</view>
					<u-scroll-list :indicator="false" class="scroll-list">
						<view v-for="(item, index) in scrollList" :key="index" class="scroll-list-item" @click="toLink(`/pages/detailsBox/detailsBox?boxId=${item.boxId}`)">
							<view class="scroll-list-item-box">
								<view class="scroll-list-item-goods"><image class="scroll-list-item-goods-img noSaveImg" :src="item.boxImg" mode=""></image></view>
								<view class="scroll-list-item-info">
									<view class="scroll-list-item-info-title single-line"><text>{{item.boxName}}</text></view>
									<view class="scroll-list-item-info-num single-line"><text>库存数量：{{item.currentNum}}</text></view>
									<view class="scroll-list-item-info-price">
										<text>￥{{item.price}}</text>
										<view class="scroll-list-item-info-price-line"></view>
									</view>
								</view>
							</view>
						</view>
					</u-scroll-list>
				</view>
				
				<view class="index-main-chunk">
					<view class="index-main-chunk-header">
						<view class="_mian-chunk-header-title"><text>推荐藏品</text></view>
						<view class="_mian-chunk-header-right" @click="toLink('/pages/collectionBoxList/collectionBoxList')"><image class="_mian-chunk-header-right-icon" src="../../static/img/right-icon.png" mode=""></image></view>
					</view>
					<view class="goods-list">
						<collection-list :list="collectionList"></collection-list>
					</view>
				</view>
			</view>
		</view>
		
		<app-footer></app-footer>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [
					require('@/static/img/index-banner.png'),
					require('@/static/img/index-banner.png'),
					require('@/static/img/index-banner.png'),
				],
				current:0,
				scrollList: [],
				collectionList:[],
			}
		},
		onLoad() {
			this.getHomePage()
		},
		onPullDownRefresh() {
			this.getHomePage()
		},
		methods: {
			toLink(link) {
				if (link) {
					uni.navigateTo({
						url:link
					})
				}
			},
			getHomePage() {
				this.$api.getHomePage().then(res => {
					// console.log(res)
					uni.stopPullDownRefresh()
					if (res.code == 200) {
						this.swiperList = res.data.bannerInfoList;
						this.scrollList = res.data.giftBoxList;
						this.collectionList = res.data.collectionInfoList;
					}
				})
			},
			swiperClick(e) {
				console.log(e)
				window.open(this.swiperList[e].bannerUrl,'_bank')
			}
		}
	}
</script>
<style lang="less" scoped>
	.index-page{
		width: 100%;
		min-height: 100vh;
		background-color: #16181D;
		display: flex;
		flex-direction: column;
		font:caption;
		.index-swiper{
			width: 100%;
			margin-top: 20rpx;
			.index-swiper-box{
				border-radius: 0 !important;
				.indicator {
					display: flex;
					flex-direction: row;
					justify-content: center;
						.indicator__dot{
							height: 8rpx;
							width: 28rpx;
							border-radius: 10rpx;
							background-color: rgba(0, 0, 0, 0.35);
							margin: 0 5px;
							overflow: hidden;
							.indicator__dot__active__line{
								width: 0%;
								height: 100%;
								background-color: #181921;
								transition: all 3s linear;
							}
						}
						.indicator__dot__active{
							.indicator__dot__active__line{
								width: 100%;
							}
						}
				    }
			}
		}
		.index-main{
			width: 100%;
			margin-top: 48rpx;
			padding: 0 32rpx;
			box-sizing: border-box;
			margin-bottom: 184rpx;
			.index-main-box{
				width: 100%;
			}
			.index-main-chunk{
				width: 100%;
				.index-main-chunk-header{
					width: 100%;
					display: flex;
					flex-wrap: nowrap;
					justify-content: space-between;
					align-items: center;
					._mian-chunk-header-title{
						font-size: 36rpx;
						font-family: PingFangSC-Medium, PingFang SC, '微软雅黑';
						font-weight: 500;
						color: #FFFFFF;
					}
					._mian-chunk-header-right{
						width: 28rpx;
						height: 40rpx;
						min-width: 28rpx;
						._mian-chunk-header-right-icon{
							width: 100%;
							height: 100%;
						}
					}
				}
				.scroll-list{
					margin-top:24rpx;
					.scroll-list-item{
						width: 610rpx;
						min-width: 610rpx;
						height: 296rpx;
						max-height: 296rpx;
						margin-right: 20rpx;
						display: flex;
						flex-direction: column;
						justify-content: flex-end;
						.scroll-list-item-box{
							width: 100%;
							height: 256rpx;
							background: #262A34;
							border-radius: 20px;
							display: flex;
							flex-wrap: nowrap;
							justify-content: space-between;
						}
						.scroll-list-item-goods{
							width: 296rpx;
							height: 100%;
							position: relative;
							.scroll-list-item-goods-img{
								width: 264rpx;
								height: 264rpx;
								position: absolute;
								top: -40rpx;
								left: 32rpx;
								border-radius: 20rpx;
							}
						}
						.scroll-list-item-info{
							width: calc(100% - 296rpx);
							padding: 32rpx 0 0 40rpx;
							box-sizing: border-box;
							.scroll-list-item-info-title{
								font-size: 32rpx;
								font-family: PingFangSC-Regular, PingFang SC, '微软雅黑';
								font-weight: 400;
								color: #FFFFFF;
							}
							.scroll-list-item-info-num{
								font-size: 28rpx;
								font-family: PingFangSC-Regular, PingFang SC, '微软雅黑';
								font-weight: 400;
								color: #5D5F7A;
								margin-top: 4rpx;
							}
							.scroll-list-item-info-price{
								font-size: 36rpx;
								font-family: Inter-Bold, Inter;
								font-weight: bold;
								color: #A06AF9;
								text-shadow: 0px 16rpx 32rpx rgba(0, 0, 0, 0.5);
								position: relative;
								margin-top: 50rpx;
								.scroll-list-item-info-price-line{
									width: 116rpx;
									height: 20rpx;
									background: #86E9A4;
									box-shadow: 0px 16rpx 32rpx 0px rgba(0, 0, 0, 0.5);
									opacity: 0.05;
									position: absolute;
									bottom: 0rpx;
									left: 0;
								}
							}
						}
					}
				}
				.goods-list{
					width: 100%;
					padding: 24rpx 0;
				}
			}
		}
	}
</style>
